home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Sources / Copy_each_icon.c next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  1.9 KB  |  64 lines  |  [TEXT/CWIE]

  1. /*    ---------------------------------------------------------------------------------------------
  2.     Find_icon, code for constructing icon suites for files and folders
  3.     
  4.     by James W. Walker
  5.     preferred e-mail: <mailto:jwwalker@kagi.com>
  6.     alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
  7.     web: <http://users.aol.com/jwwalker/>
  8.     
  9.     File: Copy_each_icon.c
  10.     
  11.     Copyright ©1997 by James W. Walker
  12.     
  13.     You may incorporate this sample code into your applications without
  14.     restriction, though the sample code has been provided "AS IS" and the
  15.     responsibility for its operation is 100% yours.
  16.     If you're going to re-distribute the source, please make it clear
  17.     that the code was descended from James W. Walker's code,
  18.     but that you've made changes.
  19.     ---------------------------------------------------------------------------------------------
  20. */
  21. #include <Icons.h>
  22. #include <Resources.h>
  23. #include "Copy_each_icon.h"
  24.  
  25. static pascal OSErr Copy_one_icon(
  26. /* --> */    ResType /* theType */,
  27. /* <-> */    Handle *theIcon,
  28. /* --- */    void * /* yourDataPtr */ )
  29. {
  30.     OSErr    err;
  31.     
  32.     if (*theIcon != NULL)
  33.     {
  34.         LoadResource( *theIcon );
  35.         err = HandToHand( theIcon );
  36.         if (err != noErr)
  37.             *theIcon = NULL;
  38.     }
  39.     
  40.     return noErr;
  41. }
  42.  
  43. /*    ------------------------------------------------------------------
  44.     Copy_each_icon            This procedure makes copies of the icon
  45.                             handles in a suite, so that they will not
  46.     be resource handles and will not be purgeable.  Note that
  47.     if the originals are resources in a file that is in use by other
  48.     programs, then DetachResource would not be appropriate.
  49.     ------------------------------------------------------------------
  50. */
  51. OSErr Copy_each_icon(
  52. /* <-> */    Handle the_suite
  53. )
  54. {
  55.     IconActionUPP    copy_icon_UPP;
  56.     OSErr            err;
  57.     
  58.     copy_icon_UPP = NewIconActionProc( Copy_one_icon );
  59.     err = ForEachIconDo( the_suite, kSelectorAllAvailableData, copy_icon_UPP, NULL );
  60.     DisposeRoutineDescriptor( copy_icon_UPP );
  61.     return err;
  62. }
  63.  
  64.